package com.alex.demo.springtest.controller;

import com.alex.demo.springtest.bean.Employee;
import com.alex.demo.springtest.service.CompanyService;
import com.alex.demo.springtest.service.TestService01;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alex.demo.springtest.bean.BigCar;
import com.alex.demo.springtest.bean.Student;
import com.alex.demo.springtest.service.TestService;

/**
 * <p>
 * 广告轮播 前端控制器
 * </p>
 *
 * @author Ht
 * @since 2019-07-16
 */
@RestController
@RequestMapping("/test")
public class TestController {

	// 引入业务层testService实现兑现.
	@Autowired
	TestService testService;
/*	TestService01 testService01;*/

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	@ResponseBody
	//@RequestParam(value = "color", required = true) String color  这个是配置前端必须传入一个参数名叫color的参数值
	public BigCar add(@RequestParam(value = "color", required = true) String color) {
		if (null != color && 0 < color.length()) {
			// 判断从前端传入参数是否有值
			BigCar bigCar;
			try {
				bigCar = testService.addColor(color);
				return bigCar;
			} catch (Exception e) {

				e.printStackTrace();
			}
		}
		return null;
	}

	@Autowired
	TestService01 testService01;
	@RequestMapping(value = "/showAll", method = RequestMethod.GET)
	@ResponseBody
	public BigCar getColor(@RequestParam(value = "test",required = true) String test){
		if(null != test && 0 < test.length()){
			BigCar bigCar;
			try{
				bigCar = testService01.addTest(test);
				return bigCar;
			}catch (Exception e1){
				e1.printStackTrace();
			}
		}
		return null;
	}

	@Autowired
	CompanyService companyService;
	@RequestMapping(value = "/showCompany", method = RequestMethod.GET)
	@ResponseBody
	public Employee getEmployee(@RequestParam(value = "person",required = true) String person,@RequestParam(value = "age",required = false)int age) throws Exception {
		if(null != person && 0 < person.length()){
			Employee employee;
			try{
				employee = companyService.addEmployee(person);
/*				employee = companyService.addAge(age);*/
/*				employee = companyService.addSalary(salary);*/
				return employee;
			}catch (Exception e2){
				e2.printStackTrace();
			}
			Employee employee1 = new Employee();
			try{
/*				employee = companyService.addEmployee(person);*/
				employee = companyService.addAge(age);
				/*employee = companyService.addSalary(salary);*/
				return employee1;
			}catch (Exception e3){
				e3.printStackTrace();
			}
		}
		return companyService.addEmployee(null);
/*		if(null != String.valueOf(age)){
			Employee employee;
			try{
				employee = companyService.addAge(age);
				return employee;
			}catch (Exception e2){
				e2.printStackTrace();
			}
		}
		return null;*/
	}
	/*public String addObj(@RequestParam Employee employee){
		this.companyService.insert(employee);
		return "sss";
	}*/
}
